<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="/operateTag" prefix="o"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>角色管理</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
	<jsp:include page="/page/head.jsp"></jsp:include>
	<script type="text/javascript">
		
		$(document).ready(function(){
			
		    $('#mgrTable').datagrid({
       			height: 500, 
		        pageSize: 20,//每页显示的记录条数，默认为10  
		        pageList: [10,15,20],//可以设置每页记录条数的列表
				nowrap: false,
        		border: true,  
				striped: true,
				collapsible: false,
				url:path+'/role/list.do',
				sortName: 'id',
				sortOrder: 'asc',
				remoteSort: false,
				idField:'id',
				columns:[[
	                {field:'ck',checkbox:true},
					{field:'name',title:'角色名称',width:120},
					{field:'permissionNames',title:'角色权限',width:500}
				]],
				pagination:true,
				rownumbers:true,
				toolbar:'#toolbar'
			});
			var p = $('#mgrTable').datagrid('getPager');
			$(p).pagination({   
		        beforePageText: '第',//页数文本框前显示的汉字  
		        afterPageText: '页    共  {pages} 页',  
		        displayMsg: '当前显示  {from} - {to} 条记录   共  {total} 条记录'
		    });
			
		});
		
		var url;
		
		function add(){
			window.location = path+"/role/init.do?type=add";
		}
		
		function edit(){
			var selected = $('#mgrTable').datagrid('getSelected');
			if(selected){
				window.location = path+"/role/init.do?type=edit&roleId="+selected.id;
			}else{
				alertBox("请选择需要编辑的角色！");
			}
		}
		
		function remove(){
			var rows = $('#mgrTable').datagrid('getSelections');
			if(rows && rows.length != 0){
				var ids = [];
				for(var i=0;i<rows.length;i++){
					ids.push(rows[i].id);
				}
				
				var submit = function (v, h, f) {
				    if (v == 'ok'){
				    	url = path +"/role/delete.do?ids="+ids.join(',')+"&t="+new Date().getTime();
						$.ajax({
						  url: url,
						  success: function(data) {
							   if(data == "1")
							   {
									$('#mgrTable').datagrid('reload');
									$('#mgrTable').datagrid('clearSelections');
									alertBox("操作成功！");
							   } else {
									alertBox("操作失败！");
							   }
						  }
						});
				    }
				    	
				    return true; //close
				};
				
				$.jBox.confirm("确定要删除吗？", "提示", submit);
				
			}else{
				alertBox("请选择需要删除的角色！");
			}
		}
		
		function refresh(){
			$('#mgrTable').datagrid('reload');
			$('#mgrTable').datagrid('clearSelections');
		}
		
		function search(){
			var name = $('#name').val();
			$('#mgrTable').datagrid('reload',{name:name});
		}
		
		function clean(){
			$('#name').attr('value','');
		}
		
	</script>

  </head>
  
  <body>
    <div class="right">
		<h1><b>角色管理</b><span><img src="<%=basePath %>images/right_h1bg2.jpg" width="3" height="29" /></span></h1>
		<div class="ri_main">
			<table width="90%" border="0" cellspacing="0" cellpadding="4">
			  <tr>
			    <td style="vertical-align: middle;">
			    	<label>名称：</label>
			    	<input class="easyui-validatebox" type="text" name="name" id="name"/>
			        <input type="button" onclick="search()" value="查询" />
			        <input type="button" onclick="clean()" value="清除" />
			    </td>
			  </tr>
			</table>
			
			<div id="toolbar">
				<a href="javascript:void(0);" onclick="add()" class="easyui-linkbutton" iconCls="icon-add">新增</a>
				<a href="javascript:void(0);" onclick="edit()" class="easyui-linkbutton" iconCls="icon-edit">编辑</a>
				<a href="javascript:void(0);" onclick="remove()" class="easyui-linkbutton" iconCls="icon-remove">删除</a>
				<a href="javascript:void(0);" onclick="refresh()" class="easyui-linkbutton" iconCls="icon-reload">刷新</a>
			</div>
		 	<table id="mgrTable">
		 		
		 	</table>  
		</div>
	</div>
  </body>
</html>
